/*
 * Copyright Hundsun Technologies Inc. All Rights Reserved.
 */

// Package contractmanager 插件管理模块，负责插件初始化等功能
package contractmanager

import (
	"github.com/spf13/cobra"
	"hundsun.com/hsl/hschain/common/config"
)

// ContractRegisterItem contract register item struct
type ContractRegisterItem struct {
	Name        string
	ContractReg func(cfg *config.PluginConfig)
	Cmd         func() *cobra.Command
}

// GetName get contract name
func (c *ContractRegisterItem) GetName() string {
	return c.Name
}

// AddContract reg contract
func (c *ContractRegisterItem) AddContract(cfg *config.PluginConfig) {
	c.ContractReg(cfg)
}

// AddCmd add Command for cli
func (c *ContractRegisterItem) AddCmd(rootCmd *cobra.Command) {
	if c.Cmd != nil {
		cmd := c.Cmd()
		if cmd == nil {
			return
		}
		rootCmd.AddCommand(cmd)
	}
}
